package it.unicam.cs.cosy.bioshape.core;

import javax.vecmath.Vector3d;

import vclip.ConvexPolyhedron;
import vclip.Matrix4dX;
import vclip.PolyTree;

class CreateExample {
	public static void main(String[] args) {
		double[] vertexCoords = { -1.0, -1.633, 0.866, 1.0, -1.633, 0.866, 0,
				-1.633, -0.866, 0, 0, 0 };

		int[][] faceIndices = { { 0, 2, 1 }, { 0, 1, 3 }, { 1, 2, 3 },
				{ 2, 0, 3 } };

		ConvexPolyhedron poly = new ConvexPolyhedron(vertexCoords, faceIndices);

		double[] points1 = new double[] { 2, 2, 2, 0, 2, 2, 0, 0, 2, 2, 0, 2,
				2, 2, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0 };

		int[][] faceIndices1 = { { 0, 1, 2, 3 }, { 0, 3, 7, 4 },
				{ 7, 6, 5, 4 }, { 6, 2, 1, 5 }, { 1, 0, 4, 5 }, { 3, 2, 6, 7 } };

		ConvexPolyhedron mioCubo = new ConvexPolyhedron(points1, faceIndices1);

		PolyTree pyramid = new PolyTree("pyramid", poly);
		PolyTree hG = new PolyTree("hourglass");

		Matrix4dX X = new Matrix4dX();
		X.setIdentity();
		X.setTranslation(new Vector3d(0, 0, -1));
		hG.addComponent("bottom", pyramid, X);

		// X.setRotation(new AxisAngle4d(1, 0, 0, Math.PI / 2));
		X.setRpy(0, 0, 180 * (Math.PI / 180));
		// X.setTranslation(new Vector3d(0, 0, -1));
		// X.setRpy(0, 0, Math.PI);
		// eseguiamo la rotazione centripeta (??)
		hG.addComponent("top", pyramid, X);

		// TODO controllare se la boundinghull va creata ogni volta da noi!!
		// teoricamente è necessario SOLO perché la generiamo qui a runtime
		hG.buildBoundingHull(PolyTree.CONVEX_HULL);
		Vector3d v = new Vector3d();
		hG.centerOfMass(v);
		System.out.println("----\n" + pyramid.getPolyhedron().toString()
				+ "\n----");
		pyramid.getTransform().setTranslation(new Vector3d(2, 3, 1));
		System.out.println("----\n" + pyramid.getPolyhedron().toString()
				+ "\n----");
		System.out.println(v);
		System.out.println(pyramid.volume());
	}
}
